﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Main.lib.util;

namespace Main.lib.graphics
{

    /*
     * Text (DisplayObject)
     * 
     * @brief   Let you draw a text on the screen
     * @version 2011.11.14
     * 
     * @author  Bruno Miguel de Oliveira Tamer <bmotamer@gmail.com>
     */
    public sealed class Text : DisplayObject
    {

     // Scope  Type       Name         Value
        public SpriteFont SpriteFont = Cache.GetFont("Arial"); //!< SpriteFont file which will be used
        public string     Content    = null;                   //!< The text which will be drawn

        /*
         * Constructor
         * 
         * @param [OPTIONAL] (string) NewContent - The text
         */
        public Text(string NewContent = null)
        {
            Content = NewContent;
        }

        /*
         * Draw the text on the screen
         * 
         * @warning This method is called automatically
         * @param   (SpriteBatch) SpriteBatch - Context which the text will be drawn
         */
        public override void Draw(SpriteBatch SpriteBatch)
        {
            if ((Invisible) || (Content == null))
                return;
            SpriteBatch.DrawString(SpriteFont, Content, Position, Color, Rotation, Origin, Scale, Effects, LayerDepth);
        }

        /*
         * Erase the text
         */
        public override void Dispose()
        {
            base.Dispose();
            SpriteFont = null;
            Content    = null;
        }

        /*
         * Get the size of the text
         * 
         * @return (Vector2) - Dimensions of the text
         */
        public Vector2 Size()
        {
            if (Content == null)
               return Vector2.Zero;
             return SpriteFont.MeasureString(Content);
        }

    }

}